Add support for pasting filenames into the filechooser. (#153212, Bastian
authorMatthias Clasen <mclasen@redhat.com>
Mon, 12 Jun 2006 15:11:39 +0000 (15:11 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 12 Jun 2006 15:11:39 +0000 (15:11 +0000)
2006-06-12  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtkfilechooserdefault.c: Add support for pasting
filenames into the filechooser.  (#153212, Bastian Nocera)

ChangeLog
ChangeLog.pre-2-10
gtk/gtkfilechooserdefault.c

index 99bb6194dbbb6c7400e408166bf003d2164ea2b5..76fb6a37a865ed2b1a6d46826627564d465d61a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-06-12  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkfilechooserdefault.c: Add support for pasting
+       filenames into the filechooser.  (#153212, Bastian Nocera)
+
 2006-06-12  Kristian Rietveld  <kris@gtk.org>
 
        * gtk/gtktreemodelfilter.[ch]
index 99bb6194dbbb6c7400e408166bf003d2164ea2b5..76fb6a37a865ed2b1a6d46826627564d465d61a7 100644 (file)
@@ -1,3 +1,8 @@
+2006-06-12  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkfilechooserdefault.c: Add support for pasting
+       filenames into the filechooser.  (#153212, Bastian Nocera)
+
 2006-06-12  Kristian Rietveld  <kris@gtk.org>
 
        * gtk/gtktreemodelfilter.[ch]
index 0927fbafb16ef7d2ffe7133b1d98172943b76974..f57778931a76fda1f059a14a01e45158f65d0deb 100644 (file)
@@ -28,6 +28,7 @@
 #include "gtkcellrenderertext.h"
 #include "gtkcellrenderertext.h"
 #include "gtkcheckmenuitem.h"
+#include "gtkclipboard.h"
 #include "gtkcombobox.h"
 #include "gtkentry.h"
 #include "gtkeventbox.h"
@@ -154,6 +155,7 @@ struct _GtkFileChooserDefaultClass
 /* Signal IDs */
 enum {
   LOCATION_POPUP,
+  LOCATION_POPUP_ON_PASTE,
   UP_FOLDER,
   DOWN_FOLDER,
   HOME_FOLDER,
@@ -313,6 +315,7 @@ static void           gtk_file_chooser_default_initial_focus          (GtkFileCh
 
 static void location_popup_handler (GtkFileChooserDefault *impl,
                                    const gchar           *path);
+static void location_popup_on_paste_handler (GtkFileChooserDefault *impl);
 static void up_folder_handler      (GtkFileChooserDefault *impl);
 static void down_folder_handler    (GtkFileChooserDefault *impl);
 static void home_folder_handler    (GtkFileChooserDefault *impl);
@@ -486,6 +489,14 @@ _gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
                             NULL, NULL,
                             _gtk_marshal_VOID__STRING,
                             G_TYPE_NONE, 1, G_TYPE_STRING);
+  signals[LOCATION_POPUP_ON_PASTE] =
+    _gtk_binding_signal_new ("location-popup-on-paste",
+                            G_OBJECT_CLASS_TYPE (class),
+                            G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+                            G_CALLBACK (location_popup_on_paste_handler),
+                            NULL, NULL,
+                            _gtk_marshal_VOID__VOID,
+                            G_TYPE_NONE, 0);
   signals[UP_FOLDER] =
     _gtk_binding_signal_new (I_("up-folder"),
                             G_OBJECT_CLASS_TYPE (class),
@@ -552,6 +563,11 @@ _gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
 #endif
 #endif
 
+  gtk_binding_entry_add_signal (binding_set,
+                               GDK_v, GDK_CONTROL_MASK,
+                               "location-popup-on-paste",
+                               0);
+
   gtk_binding_entry_add_signal (binding_set,
                                GDK_Up, GDK_MOD1_MASK,
                                "up-folder",
@@ -7338,6 +7354,51 @@ out:
   g_object_unref (handle);
 }
 
+static void
+paste_text_received (GtkClipboard          *clipboard,
+                    const gchar           *text,
+                    GtkFileChooserDefault *impl)
+{
+  GtkFilePath *path;
+
+  if (!text)
+    return;
+
+  path = gtk_file_system_uri_to_path (impl->file_system, text);
+  if (!path) 
+    {
+      if (!g_path_is_absolute (text)) 
+       {
+         location_popup_handler (impl, text);
+         return;
+       }
+
+      path = gtk_file_system_filename_to_path (impl->file_system, text);
+      if (!path) 
+       {
+         location_popup_handler (impl, text);
+         return;
+       }
+    }
+
+  if (!gtk_file_chooser_default_select_path (GTK_FILE_CHOOSER (impl), path, NULL))
+    location_popup_handler (impl, text);
+
+  gtk_file_path_free (path);
+}
+
+/* Handler for the "location-popup-on-paste" keybinding signal */
+static void
+location_popup_on_paste_handler (GtkFileChooserDefault *impl)
+{
+  GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl),
+                                                     GDK_SELECTION_CLIPBOARD);
+  gtk_clipboard_request_text (clipboard,
+                             (GtkClipboardTextReceivedFunc) paste_text_received,
+                             impl);
+}
+
+
 /* Implementation for GtkFileChooserEmbed::should_respond() */
 static gboolean
 gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed)